package com.xd.core.system.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 
 * </p>
 *
 * @author ZX
 * @since 2024-07-25
 */
@Accessors(chain = true)
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="GroupInfo对象", description="")
public class GroupInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "组id")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "上级id")
    private Integer pid;

    @ApiModelProperty(value = "组名")
    private String groupName;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING,timezone = "GMT+8")
    @TableField(fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING,timezone = "GMT+8")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

    @ApiModelProperty(value = "归属公司id")
    private Integer companyId;

    @ApiModelProperty(value = "描述")
    private String remark;

    @TableField(exist = false)
    @ApiModelProperty(value = "已经选择")
    private boolean groupInfoStatus;

    @TableField(exist = false)
    @ApiModelProperty(value = "子级")
    private List<GroupInfo> children;

    @TableField(exist = false)
    @ApiModelProperty(value = "部门人数")
    private int userCounts;

    @TableField(exist = false)
    @ApiModelProperty(value = "部门员工")
    private List<GroupUser> users;

    public void addUserCounts(int count) {
        this.userCounts=userCounts+count;
    }

    public void addChild(GroupInfo child) {
        if (this.children == null)
            this.children = new ArrayList<>();
        this.children.add(child);
    }

    public void addUsers(GroupUser groupUser) {
        if (this.users == null)
            this.users = new ArrayList<>();
        this.users.add(groupUser);
    }
    @Data
    public static class GroupUser{
        @ApiModelProperty(value = "员工ID")
        private Integer id;
        @ApiModelProperty(value = "员工姓名")
        private String userName;
        @ApiModelProperty(value = "部门ID")
        private Integer groupId;
        @ApiModelProperty(value = "是否已选择")
        private boolean status;

    }

}
